package com.ym.manager.admin.tbUser;

import com.ym.manager.admin.tbUser.model.TbUserInfo;
import com.ym.utils.Pages;
import com.ym.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/tbUser/")
public class TbUserController {

    @Autowired
    private TbUserService tbUserService;

    /**
     * 页面：关系列表
     * @return
     */
    @RequestMapping("relation")
    public String relation(){
        return "tbUser/relation";
    }

    /**
     * 功能：关系列表
     * @return
     */
    @RequestMapping("relationData")
    @ResponseBody
    public String relationData(@RequestParam(defaultValue = "0") int page,
                               @RequestParam(defaultValue = "10") int limit,
                               @RequestParam(defaultValue = "0") int mcode){
        Map<String,Object> map = ResultUtil.result();
        try {
            Pages<TbUserInfo> pages = tbUserService.subList(page,limit,mcode);
            //查询数据
            map.put("data",pages.getList());
            map.put("count",pages.getTotal());
        }catch (Exception e){
            map.put("msg","系统异常");
            map.put("code",-1000);
            e.printStackTrace();
        }
        return ResultUtil.toJSON(map);
    }

    /**
     * 功能：获取上级信息
     * @param mcode 邀请码
     * @return
     */
    @RequestMapping("supUser")
    @ResponseBody
    public String supUser(int mcode){
        Map<String,Object> map = ResultUtil.result();
        try {
            TbUserInfo userInfo = tbUserService.supUser(mcode);
            //查询数据
            map.put("data",userInfo);
        }catch (Exception e){
            map.put("msg","系统异常");
            map.put("code",-1000);
            e.printStackTrace();
        }
        return ResultUtil.toJSON(map);
    }
}
